package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 老杨
 * @version 1.0
 */
@Api(tags = "管理端订单接口")
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;

    @ApiOperation(value = "订单查询接口")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearchconditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("接收 参数 {}",ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }


    @ApiOperation(value = "返回订单状态对应数量接口")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO statistics = orderService.statistics();
        return Result.success(statistics);
    }


    @ApiOperation(value = "返回订单详细信息接口")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    @ApiOperation(value = "接单接口")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单信息"+ordersConfirmDTO.getId()+""+ordersConfirmDTO.getStatus());
        Long id = ordersConfirmDTO.getId();
        orderService.confirm(id);
        return Result.success();
    }

    @ApiOperation(value = "拒单接口")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO rejectionDTO){
        orderService.rejection(rejectionDTO);
        return Result.success();
    }

    @ApiOperation(value = "取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @ApiOperation(value = "派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     *
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("id") Long id) {
        orderService.complete(id);
        return Result.success();
    }
}
